import request from "@utils/request";
import { R, LoginForm, User } from "./model";

export const login = (loginData: LoginForm) => {
    return request<R<User>>({
        url: "/api/user/login",
        method: "POST",
        data: loginData
    }).then((resp: any) => {
        return resp;
    });
};

export const logout = () => {
    return request<R<string>>({
        url: "/api/user/logout",
        method: "get",
    }).then((resp: any) => {
        console.log(resp);

        return resp;
    });
};

export const getCurrentUser = () => {
    return request<R<User>>({
        url: "/api/user/getCurrentUser",
        method: "get",

    }).then((resp: R<User>) => {
       
        console.log("获取当前用户：" + resp.data.username);
        console.log("当前用户头像：" + resp.data.salt);
        return resp;
    });
}

export const update = (user:User) => {
    console.log("修改："+user);
    
    return request<R<string>>({
        url: "/api/user",
        method: "put",
        data:user
    }).then((resp: any) => {
        console.log(resp);
        return resp;
    });
};
